<template>
  <div>
    <div style="width: 100%; height: 100px">
      <b>重新登录测试 : </b><button @click="timeoutReLogin()">请求</button><br />
    </div>
    <div style="width: 100%; height: 400px">
      <b>GET : </b><br />
      &nbsp;&nbsp;&nbsp;url : <input v-model="gurl" style="width: 500px" /><button @click="send('get')">请求</button
      ><br />
      &nbsp;&nbsp;&nbsp;响应：<textarea style="width: 100%; height: 300px" v-model="getRes" />
    </div>
    <div style="width: 100%; height: 600px">
      <b>POST:</b><br />
      &nbsp;&nbsp;&nbsp;url : <input v-model="purl" style="width: 500px" /><button @click="send('post')">请求</button
      ><br />
      &nbsp;&nbsp;&nbsp;参数 ：<textarea v-model="reqBody" style="width: 100%; height: 150px" /><br />
      &nbsp;&nbsp;&nbsp;响应 ：<textarea style="width: 100%; height: 300px" v-model="postRes" /><br />
    </div>
    <div style="width: 100%; height: 400px">
      <b>get Key : </b><br />
      &nbsp;&nbsp;&nbsp;key : <input v-model="keyname" style="width: 500px" /><button @click="getKey('')">请求</button
      ><br />
      &nbsp;&nbsp;&nbsp;响应：<textarea style="width: 100%; height: 300px" v-model="keyval" />
    </div>
  </div>
</template>

<script>
import { getParamValFromUrl } from '@/utils/common.js'
import { getAction, postAction } from '@/api/manage'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'

export default {
  name: 'InterfaceDo',
  components: {},
  data() {
    return {
      gurl: '/projectBuild/removeProjectTest?id=',
      purl: '/reportHome/projectListHot',
      reqBody: '{size:10,current:1}',
      getRes: '',
      postRes: '',
      keyname: '',
      keyval: '',
    }
  },
  mounted() {},
  created() {},
  computed: {},
  methods: {
    send(type) {
      if (type == 'get') {
        getAction(this.gurl, {}).then((res) => {
          if (res.code == 200) {
            this.$message.success('操作成功')
          } else {
            this.$message.success('操作失败')
          }
          this.getRes = JSON.stringify(res)
        })
      }
      if (type == 'post') {
        postAction(this.purl, eval('(' + this.reqBody + ')')).then((res) => {
          if (res.code == 200) {
            this.$message.success('操作成功')
          } else {
            this.$message.success('操作失败')
          }
          this.postRes = JSON.stringify(res)
        })
      }
    },
    timeoutReLogin() {
      // console.log(process.env.VUE_APP_BASE_URL+"/blank?backUrl="+encodeURI(this.$route.path));
      console.log(
        this.VUE_BASE_URL +
          '/blank?yamitoken=$TOKEN$&backUrl=' +
          encodeURI('/approval?projectBuildId=13530a25e13e4caba0dc06a2f06113a9')
      )
      if (window.timeoutReload) {
        window.timeoutReload(
          JSON.stringify({
            url:
              this.VUE_BASE_URL +
              '/blank?yamitoken=$TOKEN$&backUrl=' +
              encodeURI('/approval?projectBuildId=13530a25e13e4caba0dc06a2f06113a9'),
          })
        )
      }
    },
    getKey() {
      if (this.keyname) {
        getAction('/home/getKeyCheck',{name:this.keyname}).then((res) => {
          if (res.code == 200 && res.result) {
            this.keyval = res.result
          }
        })
      }
    },
  },
  filters: {},
}
</script>
